package com.runa.monitor.platinterface.backwork.impl;

import com.runa.monitor.platinterface.backwork.function.AbstractTaskFunction;
import com.runa.monitor.platinterface.backwork.function.TaskFunction;
import com.runa.monitor.platinterface.netservice.connect.commstatus.CommStatus;
import com.runa.monitor.platinterface.netservice.equipment.NetEqu;
import com.runa.rccprotocol.dto.AffirmDeny;
import com.runa.rccprotocol.dto.runa.RunaConcenAffirmDeny;
import lombok.extern.slf4j.Slf4j;

/**
 * 2025/2/19 15:30
 * zhangYB
 */
@Slf4j
public class ApportionFunction extends AbstractTaskFunction {

    private NetEqu netEqu;
    private int priority = 0;
    private String msg;

    public ApportionFunction(NetEqu netEqu, int priority) {
        this.netEqu = netEqu;
        this.priority = priority;
    }

    public ApportionFunction(NetEqu netEqu, int priority, String msg) {
        this.netEqu = netEqu;
        this.priority = priority;
        this.msg = msg;
    }

    @Override
    public void doApply(CommStatus status, Object o) {
        if (!CommStatus.OK.equals(status)) {
            netEqu.setRequestTask(null);
        }
        if (o instanceof AffirmDeny) {
            AffirmDeny affirmDeny = (AffirmDeny)o;
            if (!affirmDeny.getData()) {
                netEqu.setRequestTask(null);
            }
        }
    }

    @Override
    public int getPriority() {
        return priority;
    }

    @Override
    public String getMessage() {
        return msg;
    }
}
